/**
 * 
 */
package com.store;

import java.util.ArrayList;
import java.util.List;

import com.jedi.BaseObj;
import com.tss.util.DbConn;
import com.tss.util.DbRs;

/**
 * @author wevjoso
 *
 */
public class SevgradeMgr extends BaseObj{
	
	
public Sevgrade get(int sgid){
		
		
		clearErr();
		Sevgrade sevgrade = new Sevgrade();
		DbConn conn = new DbConn();
		try {
			String sql = "";
			sql = "select * from sevgrade where sgid = ?";
			conn.prepare(sql);
			conn.setInt(1,sgid);
			DbRs rs = conn.executeQuery();
			if (rs == null || rs.size() ==0) return null;
			sevgrade.setSgid(getInt(rs,0,"sgid"));
			sevgrade.setSgname(get(rs,0,"sgname"));
			
			
		
			return sevgrade;
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
	}
	
	
	public List get(String otherSQL,String orderField) {
		clearErr();
		DbConn conn = new DbConn();
		DbRs rs = null;
		try {
			String sql = "";
			sql = "select * from sevgrade where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals("")) 
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
		if (rs != null && rs.size() >0) {
			List r = new ArrayList();
			for(int i=0;i<rs.size();i++) {
				Sevgrade task = new Sevgrade();
				task.setSgid(getInt(rs,i,"sgid"));
				task.setSgname(get(rs,i,"sgname"));
			
			
				r.add(task);
			}
			return r;
		}
		return null;
	}
	/**
	 * 合同服务等级下拉菜单
	 * @return
	 */
	public List getGradeGroupBy() {
		clearErr();
		DbConn conn = new DbConn();
		DbRs rs = null;
		try {
			String sql = "";
			sql = "select sgid,sgname from sevgrade where 1=1 group by sgid,sgname order by sgid ";
			
			conn.prepare(sql);
			rs = conn.executeQuery();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
		if (rs != null && rs.size() >0) {
			List r = new ArrayList();
			for(int i=0;i<rs.size();i++) {
				Sevgrade sevgrade = new Sevgrade();
				sevgrade.setSgid(getInt(rs,i,"sgid"));
				sevgrade.setSgname(get(rs,i,"sgname"));
			
				
				
				r.add(sevgrade);
			}
			return r;
		}
		return null;
	}
	
}
